package com.example.quartz.config;

import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;

@Configuration
public class QuartzConfig {

    @Autowired
    private SchedulerFactoryBean schedulerFactoryBean;

    /**
     * 注入job 创建工厂
     * @return
     */
    @Bean
    public SpringBeanJobFactory springBeanJobFactory(){
        return new SpringBeanJobFactory();
    }

    /**
     * 注入 Scheduler 调度器
     * @return
     */
    @Bean
    public Scheduler scheduler(){
        return schedulerFactoryBean.getScheduler();
    }
}
